package com.example.d_thymeleaf_validator.validator;

import com.example.enums.AreaEnum;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author zk
 * @date 2019-10-28 14:56
 */
public class AreaValidator implements ConstraintValidator<Area, Object> {

    private AreaEnum areaEnum;

    @Override
    public void initialize(Area area) {
        areaEnum = area.area();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return areaEnum.equals(value);
    }
}

